package com.lagou.edu.controller;

import com.lagou.edu.pojo.AuthCode;
import com.lagou.edu.service.MailService;
import com.lagou.edu.service.ValicateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lyj
 * @Title: UserController
 * @ProjectName homework-parent
 * @Description: TODO
 * @date 2021/1/2 20:12
 */
@RestController
@RequestMapping("/email")
public class EmailController {

    @Autowired
    private MailService mailService;

    @Autowired
    private ValicateService valicateService;

    /**
     * 发送验证码到邮箱
     * @param email
     * @param
     * @return
     */
    @GetMapping("/toemail/{email}")
    public boolean email(@PathVariable String email){
        int random=(int) (Math.random()*9+1)*100000;
        mailService.sendSimpleEmail(email, "欢迎注册", "验证码："+random);
        AuthCode authCode = new AuthCode();
        authCode.setCode(String.valueOf(random));
        authCode.setEmail(email);
        valicateService.saveAuthCode(authCode);
        System.out.println("邮箱存入数据库成功");
        return true;
    }



}
